home *** CD-ROM | disk | FTP | other *** search
- Path: columba.udac.uu.se!news
- From: Enrico Savazzi <enrico.savazzi@pal.uu.se>
- Newsgroups: comp.lang.c
- Subject: Re: How to copy from Array to Array ?
- Date: Mon, 05 Feb 1996 17:14:29 +0100
- Organization: Uppsala University
- Message-ID: <31162CE5.43C0@pal.uu.se>
- References: <4f3ec3$3vp5@unix1.sncc.lsu.edu>
- NNTP-Posting-Host: esavazzi.pal.uu.se
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (WinNT; I)
-
- Rajabhushan Cherukuri wrote:
- >
- > Hello Everybody:
- > I have a simple question on using Arrays and Pointers. Let's say
- > that i have two arrays declared as,
- > double Array1[15000], and char Array2[15000].
- > How do i sequentially copy elements from Array1 to Array2 using "sprintf"
- > and "pointers" and how i can print the values in Array2. Any suggestions
- > will be appreciated.
- >
- > RAJABHUSHAN CHERUKURI (RAJ)
- > LOUISIANA STATE UNIVERSITY
- > garaja@unix1.sncc.lsu.edu
-
- I have not tried this, but it is what I would do to develop the
- piece of software you need:
-
- 1-use sprintf() to print a double to a temporary buffer
- 2-determine the length of the string in the buffer (with
- strlen())
- 3-Copy the string bytes to Array2. Keep a pointer that tells you
- the last used byte in Array2.
- 4-Append to the used portion of Array2 a character to indicate
- the end of a string containing the double value. Increment by
- one the pointer to last-used-byte.
- 5-repeat until you have all the doubles lined up in Array2.
-
- To print, parse Array2 and isolate one by one all the substrings
- terminated by the character you used to separate the values. As
- a separator character, you can use any character except 0-9, e,
- E, .(point), +, - (i.e., all characters that can be part of a
- double representation). Do not use '\0' (null), because this is
- the end-of-string marker, and you would be unable to use
- standard string functions after the first null.
-
- E. Savazzi
-